package demo04;

import java.util.function.Supplier;

/**
 * @author: WangPeng
 * @createTime: 2022/11/04 16:28
 * @description:
 * @version: v1.0
 */
//实例方法引用  inst::instMethod         (args) -> inst.instMethod(args)
public class Test03 {
    public static void main(String[] args) {
        People people = new People("小明", 21);
        //该lambda表达式: 对象名.实例方法（）。
        Supplier<String> supplier1 = ()->people.getName();
        //可以替换为实例方法引用--->对象名::实例方法
        Supplier<Integer> supplier2 = people::getAge;

        System.out.println(supplier1.get());
        System.out.println(supplier2.get());
    }
}
class People {
    private String name;
    private Integer age;

    public People(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "People{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
